/* Copyright (c) [2007-2022] [Jianjun Jiang <8192542@qq.com>]. Licensed under MIT License. */

#ifndef _X_TICK_H
#define _X_TICK_H

#include <stdint.h>    

/* 步进1ms，最大延迟为 24 天（32位整型溢出特性） */
#define time_after(a, b)   (((int32_t)(b) - (int32_t)(a) < 0))
#define time_before(a, b)  time_after(b, a)
#define time_after_eq(a, b) (((int32_t)(a) - (int32_t)(b) >= 0))
#define time_before_eq(a, b) time_after_eq(b, a)

#define TIMEOUT_MS(ms)  (ms)       

extern volatile uint32_t Ticks_Num_1Ms;

static __inline void delay_ms(uint32_t ms)
{
	uint32_t ticks_old=Ticks_Num_1Ms;
	while(time_before(Ticks_Num_1Ms,ticks_old+TIMEOUT_MS(ms)));
}

#endif /* _X_TICK_H */